package com.itheima.prtice;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class ResSetContex extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //响应中乱码问题setContentType("text/html;charset=utf-8");
//        String S="字符输出流乱码问题";
//        resp.setContentType("text/html;charset=utf-8");
//        PrintWriter writer = resp.getWriter();
//        writer.write(S);
        //字节输出流
//        ServletOutputStream stream = resp.getOutputStream();
//        stream.write(S.getBytes());
//设置响应头---控制缓存setDateHeader()一般缓存静态资源;Expires设置响应头，但值是毫秒值
//        String str="控制缓存时间";
//        resp.setDateHeader("Expires",System.currentTimeMillis()+1*60*60*1000);
//        resp.getOutputStream().write(str.getBytes());
//        resp.getWriter().write(str);
//设置响应头刷新 setHeader("refresh",2;URL="/index.jsp"")
//        String str="输入错误，2秒后跳转到登录页面";
//        resp.getWriter().write(str);
//        resp.setHeader("refresh","2;URL=/index.jsp");
//重定向sendRedirect()重定向请求响应两次，地址栏发生改变为重定向后的
//resp.sendRedirect("Servlet01");
//请求中的共享数据setAttribute() getAttribute()
//req.setAttribute("name","aa");



    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
